layui.use(['form','layer','jquery'],function(){
    var form = layui.form,
        layer =layui.layer,
        $ = layui.jquery;
    //添加验证规则
    form.verify({
        userNameNotNull : function(value, item){
            if(value.trim() ==""){
                return "请输入登录名";
            }
        },
        pwdNotNull : function(value, item){
            if(value.trim() ==""){
                return "请输入密码";
            }
        },
        codeNotNull : function(value, item){
            if(value.trim() ==""){
                return "请输入验证码";
            }
        }
    });

    //登录按钮
    form.on("submit(login)",function(data){
        $(this).text("登录中...").attr("disabled","disabled").addClass("layui-disabled");
        $.post('sys/login/login',data.field,function(data){
            if(data.code === 1){
                layer.msg(data.msg,{icon:6,time:1000});
                setTimeout(function(){
                    window.location.reload();
                },1000);
                return false;
            }
            layer.msg(data.msg,{icon:6,time:1000});
            setTimeout(function(){
                window.location.href = "page/index.jsp";
            },1000);
        });
        return false;
    });

    //表单输入效果
    $(".loginBody .input-item").click(function(e){
        e.stopPropagation();
        $(this).addClass("layui-input-focus").find(".layui-input").focus();
    });
    $(".loginBody .layui-form-item .layui-input").focus(function(){
        $(this).parent().addClass("layui-input-focus");
    });
    $(".loginBody .layui-form-item .layui-input").blur(function(){
        $(this).parent().removeClass("layui-input-focus");
        if($(this).val() != ''){
            $(this).parent().addClass("layui-input-active");
        }else{
            $(this).parent().removeClass("layui-input-active");
        }
    });
});
//获取验证码
function sendCode() {
    document.getElementById("myCode").src="sys/login/verifyCode?"+Math.random();
}